﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using OTS.Model;
using OTS.BLL;

public partial class Member_Evaluation : OTS.MemberPage
{
    protected string strPro;
    protected string strConent;
    custom cus = new custom();
    evaluation eval = new evaluation();
    EvaluationBLL eBLL = new EvaluationBLL();
    DataTable dt = new DataTable();
    StringBuilder sb = new StringBuilder();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!TestLogin(HttpContext.Current))
        {
            Response.Redirect("index.aspx");
            return;
        }
        if (!Page.IsPostBack)
        {
            int proID=Convert.ToInt32(Request.QueryString["proID"]);
            BindPro(proID);
        }
    }

    protected void BindPro(int proID)
    {
        string count = "0";
        ProductBLL proBLL = new ProductBLL();
        dt = proBLL.GetAllProduct(" where proID=" + proID);
        if (dt.Rows.Count > 0)
        {
            sb.Append("<div class=\"p-img\">");
            sb.AppendFormat("<a target=\"_blank\" href=\"product.aspx?proID=" + proID + "\" title=\"" + dt.Rows[0]["title"].ToString() + dt.Rows[0]["proNO"].ToString() + "\">");
            string imgUrl = dt.Rows[0]["bigImg_pic"].ToString();
            if (imgUrl=="")
            {
                sb.AppendFormat("<img src=\"img/yes_picture.gif\" />");
            }
            else
            {
                string strUrl = imgUrl.Replace(@"\", "/");
                string strUrls = strUrl.Replace(@"~", ".");
                sb.AppendFormat("<img  width=\"135\" height=\"170\" src=\"" + strUrls + "\" />");
            }
            sb.Append("</a>");
            sb.Append("</div>");
            sb.Append("<div class=\"p-name\">");
            sb.AppendFormat("商品名称： <a target=\"_blank\" href=\"product.aspx?proID=" + proID + "\">" + dt.Rows[0]["title"].ToString() + dt.Rows[0]["proNO"].ToString() + "</a>");
            sb.Append("</div>");
            sb.AppendFormat("<div class=\"price1\" style=\"margin-top: 8px; font-size: 14px;\">价格：￥" + dt.Rows[0]["retailPrice"].ToString() + "</div>");
            DataTable dTable = eBLL.GetProETotal(proID);
            if (dTable.Rows[0]["total"].ToString()!="0")
            {
                count = dTable.Rows[0]["total"].ToString();
            }
            sb.AppendFormat("<div style=\"margin-top: 8px;\">评论数：<span>" + count + "</span>条</div>");
        }
        strPro = sb.ToString();
    }

    //提交评论
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        //string title = Request.Form["title"];
        //string pros = Request.Form["pros"];
        //string cons = Request.Form["cons"];
        string content = Request.Form["content"];
        cus = GetCustom(HttpContext.Current);
        int proID = Convert.ToInt32(Request.QueryString["proID"]);
        if (content != "")       //title != "" && content != "" && pros != "" && cons != ""
        {
            ClientScript.RegisterStartupScript(GetType(), "", "<script>savingComment();</script>");
            eval.cusID = cus.cusID;
            eval.proID = proID;
            eval.experience = content;
            //eval.etitle = title;
            //eval.advantages = pros;
            //eval.shortage = cons;
            dt = eBLL.GetProE(proID);
            if (dt.Rows.Count==0)
            {
                if (eBLL.Add(eval))
                {
                    OTS.Common.Jscript.Alert("评价成功！");
                    BindPro(proID);
                }
            }
            else
            {
                OTS.Common.Jscript.Alert("该商品您之前已评价！");
                BindPro(proID);
                return;
            }
        }
        else
        {
            //ClientScript.RegisterStartupScript(GetType(), "", "<script>Errorpanel();</script>");
            
        }
    }
}
